package com.air.common.util;

/**
 * <p>Title: ͨ�üӽ���</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: �Ϻ���άͨ�ż������޹�˾</p>
 * @author Selle Wu
 * @version 1.0
 * history:
 * Date:          Resp        Comment
 *                            Create
 * 2005-08-12     Selle Wu    Modify
 */

import java.security.*;

public class Md5 {
  public Md5() {
  }

  public static String byte2hex(byte[] b) { //������ת�ַ�
    String hs = "";
    String stmp = "";
    for (int n = 0; n < b.length; n++) {
      stmp = (Integer.toHexString(b[n] & 0XFF));
      if (stmp.length() == 1)
        hs = hs + "0" + stmp;
      else
        hs = hs + stmp;
      if (n < b.length - 1)
        hs = hs;
    }
    return hs.toUpperCase();
  }

  public static String getMD5(String password) {
    String returnStr = null;
    try {
      java.security.MessageDigest alga = java.security.MessageDigest.
          getInstance("MD5");

      alga.update(password.getBytes());
      byte[] digesta = alga.digest();
      returnStr = byte2hex(digesta);
    }
    catch (Exception e) {}
    return returnStr;
  }

//  public static void main(String args[]) {
//
//    Md5 m = new Md5();
//
//    System.out.println("MD5 Test suite:");
//    System.out.println("MD5(\"\"):" + m.getMD5(""));
//    System.out.println("MD5(\"a\"):" + m.getMD5("a"));
//    System.out.println("MD5(\"abc\"):" + m.getMD5("abc"));
//    System.out.println("MD5(\"message digest\"):" + m.getMD5("message digest"));
//    System.out.println("MD5(\"abcdefghijklmnopqrstuvwxyz\"):" +
//                       m.getMD5("abcdefghijklmnopqrstuvwxyz"));
//    System.out.println(
//        "MD5(\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"):" +
//        m.getMD5(
//        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"));
//
//  }

}